/**
 * <strong>Title : ReportController.java<br>
 * </strong> <strong>Package : cn.b.sky.mes.mm.controller<br>
 * </strong> <strong>Description : </strong>@类注释说明写在此处@<br>
 * <strong>Create on : 2016年3月4日 下午2:09:31<br>
 * </strong>
 * <p>
 * @author dapeng.li<br>
 * @version <strong>v1.0.0</strong><br>
 * <br>
 *          <strong>修改历史:</strong><br>
 *          修改人 | 修改日期 | 修改描述<br>
 *          -------------------------------------------<br>
 * <br>
 * <br>
 */
package cn.b.sky.mes.mm.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.b.sky.mes.mm.model.InOutBook;
import cn.b.sky.mes.mm.model.InventoryItemQuery;
import cn.b.sky.mes.mm.model.InventoryQuery;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.b.sky.mes.mm.constants.MmConstant;
import cn.b.sky.mes.mm.model.condition.InOutBookCondition;
import cn.b.sky.mes.mm.model.condition.InventoryItemQueryCondition;
import cn.b.sky.mes.mm.model.condition.InventoryQueryCondition;
import cn.b.sky.mes.mm.service.ReportService;
import cn.b.sky.common.file.Excel;
import cn.b.sky.common.file.ExcelModel;
import cn.b.sky.common.file.GridModel;
import cn.b.sky.user.controller.SecurityController;

/**
 * <strong>Title : ReportController.java<br></strong>
 * <strong>Package : cn.b.sky.mes.mm.controller<br></strong>
 * <strong>Description : </strong>物流报表控制器<br> 
 * <strong>Create on : 2016年3月4日 下午2:09:31<br></strong>
 * <p> 
 * @author dapeng.li<br>
 * @version <strong>v1.0.0</strong><br>
 * <br>
 * <strong>修改历史:</strong><br>
 * 修改人    |    修改日期    |    修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */
@Controller
@RequestMapping("inOutBook")
public class ReportController extends SecurityController {

  @Resource
  ReportService reportService;

  @RequestMapping("inOutBookList")
  public String inOutBookList(Model model, @ModelAttribute("condition") InOutBookCondition condition, String navTabId,
      HttpSession session) {
    condition.setSiteCode(getSiteCode());
    List<InOutBook> list = reportService.selectInOutBookListByCondition(condition);
    int count = reportService.selectInOutBookCountByCondition(condition);
    session.setAttribute(MmConstant.INOUTBOOK_CONDITION, condition);
    condition.setData(list);
    condition.setTotalCount(count);
    model.addAttribute("page", condition);
    model.addAttribute("navTabId", navTabId);
    return "mm/inOutBook/inOutBookList";
  }

  @RequestMapping("exportInOutBookToExcel")
  public void exportOutBookListToExcel(HttpServletResponse response, String tableMap,
      @ModelAttribute("condition") InOutBookCondition condition, String navTabId, HttpSession session)
      throws IOException {
    InOutBookCondition condition0 = (InOutBookCondition) session.getAttribute(MmConstant.INOUTBOOK_CONDITION);
    if (condition0 != null) {
      condition = condition0;
    }
    condition.setSiteCode(getSiteCode());
    List<Map<String, Object>> list = reportService.selectAllInOutBookListByCondition(condition);
    Excel excel = new Excel();
    excel.setTableMap(tableMap);
    ExcelModel model = new GridModel(excel.getTable("iTable"), list);
    excel.addExcelModel(model);
    String title = getImeViewMessageI18n(null, "inOutBook.C");
    excel.doExport(response, title);
  }

  @RequestMapping("inventoryQueryList")
  public String inventoryQueryList(Model model, @ModelAttribute("condition") InventoryQueryCondition condition,
      String navTabId, HttpSession session) {
    condition.setSiteCode(getSiteCode());
    List<InventoryQuery> list = reportService.selectInventoryListByCondition(condition);
    int count = reportService.selectInventoryCountByCondition(condition);
    session.setAttribute(MmConstant.INVENTORYQUERY_CONDITION, condition);
    condition.setData(list);
    condition.setTotalCount(count);
    model.addAttribute("page", condition);
    model.addAttribute("navTabId", navTabId);
    return "mm/inOutBook/inventoryQueryList";
  }

  @RequestMapping("inventoryItemQueryList")
  public String inventoryItemQueryList(Model model, @ModelAttribute("condition") InventoryItemQueryCondition condition,
      String navTabId, HttpSession session) {
    condition.setSiteCode(getSiteCode());
    List<InventoryItemQuery> list = reportService.selectInventoryItemListByCondition(condition);
    int count = reportService.selectInventoryCountByCondition(condition);
    session.setAttribute(MmConstant.INVENTORYQUERYITEM_CONDITION, condition);
    condition.setData(list);
    condition.setTotalCount(count);
    model.addAttribute("page", condition);
    model.addAttribute("navTabId", navTabId);
    return "mm/inOutBook/inventoryItemQueryList";
  }

  @RequestMapping("exportInventoryQueryToExcel")
  public void exportInventoryQueryToExcel(HttpServletResponse response, String tableMap,
      @ModelAttribute("condition") InventoryQueryCondition condition, String navTabId, HttpSession session)
      throws IOException {
    InventoryQueryCondition condition0 = (InventoryQueryCondition) session
        .getAttribute(MmConstant.INVENTORYQUERY_CONDITION);
    if (condition0 != null) {
      condition = condition0;
    }
    condition.setSiteCode(getSiteCode());
    List<Map<String, Object>> list = reportService.selectAllInventoryListByCondition(condition);
    Excel excel = new Excel();
    excel.setTableMap(tableMap);
    ExcelModel model = new GridModel(excel.getTable("iTable"), list);
    excel.addExcelModel(model);
    String title = getImeViewMessageI18n(null, "inventoryQuery.C");
    excel.doExport(response, title);
  }

  @RequestMapping("exportInventoryItemQueryToExcel")
  public void exportInventoryItemQueryToExcel(HttpServletResponse response, String tableMap,
      @ModelAttribute("condition") InventoryItemQueryCondition condition, String navTabId, HttpSession session)
      throws IOException {
    InventoryItemQueryCondition condition0 = (InventoryItemQueryCondition) session
        .getAttribute(MmConstant.INVENTORYQUERYITEM_CONDITION);
    if (condition0 != null) {
      condition = condition0;
    }
    condition.setSiteCode(getSiteCode());
    List<Map<String, Object>> list = reportService.selectAllInventoryItemListByCondition(condition);

    Excel excel = new Excel();
    excel.setTableMap(tableMap);
    ExcelModel model = new GridModel(excel.getTable("iTable"), list);
    excel.addExcelModel(model);
    String title = getImeViewMessageI18n(null, "inventoryItemQuery.C");
    excel.doExport(response, title);

  }

}
